package com.boang.lock;

import java.util.concurrent.locks.ReentrantLock;

/*
    @author:sa
    @date:2024/11/26 13:58
*/
public class TicketDemoLock05 implements Runnable {
    private int num = 20;
    public ReentrantLock lock = new ReentrantLock();

    @Override
    public void run() {
        while (true) {
            lock.lock();
            if (num > 0) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + ":" + num--);
            }
            lock.unlock();
        }
    }
}